{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "my = pd.read_csv('maoyanfilms_clean.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    " t_list = [] #存放电影类型的列表\n",
    "for i in range(0,len(my['films_type'])):\n",
    "   if type(my['films_type'][i])== str:\n",
    "    s_t = my['films_type'][i].split(',')\n",
    "    for j in s_t:\n",
    "        if j not in t_list:\n",
    "            t_list.append(j)  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "t_list.remove(' 青春 励志 爱情 ')\n",
    "t_list.remove('  ')\n",
    "t_list.remove(' 惊悚；恐怖；悬疑；爱情 ')\n",
    "t_list.remove(' 灵异/喜剧/悬疑 ')\n",
    "t_list.remove(' 爱情 恐怖 ')\n",
    "t_list.remove(' 爱情 / 喜剧 / 青春 ')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "count_type_list = [0]*len(t_list)  #用来记录每个类型多少部的\n",
    "for i in range(0,len(my['films_type'])):\n",
    "   if type(my['films_type'][i])== str:\n",
    "    s_list = my['films_type'][i].split(',')\n",
    "    for j in s_list:\n",
    "        for k in range(0,len(t_list)):\n",
    "            if j== t_list[k]:\n",
    "                count_type_list[k] +=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "c = (\n",
    "    Bar()\n",
    "    .add_xaxis(t_list[::-1])\n",
    "    .add_yaxis(\"类别\", count_type_list[::-1])\n",
    "    .reversal_axis()\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(position=\"right\"))\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"电影类别分布情况\"))\n",
    "    .render(\"不同类型电影发行数统计.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
